//
//  NavigaionView.m
//  StudentClient
//
//  Created by 张宁宁 on 16/5/31.
//  Copyright © 2016年 lirenkj. All rights reserved.
//

#import "NavigationView.h"
#import "ImageUtil.h"

@interface NavigationView()

@end

@implementation NavigationView
@synthesize titleLable;
@synthesize navDelegate;

-(instancetype)initViewWithTitleName:(NSString*)titlename leftBtnImage:(NSString*)leftimage rithtBtnImage:(NSString*)rightimage {
    if (self = [super init]) {
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 64);
        self.backgroundColor = RGBColor(35, 62, 74);
        titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH  , 44)];
        titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.text = titlename;
        titleLable.font = FontWithNameBold(18);
        titleLable.textColor = [UIColor whiteColor];
        titleLable.backgroundColor = [UIColor clearColor];
        [self addSubview:titleLable];
        if (rightimage) {
            
            self.rbtn = [UIButton buttonWithType:UIButtonTypeCustom];
            self.rbtn.frame = CGRectMake(SCREEN_WIDTH-44, 20, 44, 44);
            [self.rbtn setImage:[ImageUtil getImageByName:rightimage] forState:UIControlStateNormal];
            [self.rbtn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
            self.rbtn.tag = RIGHTBTN;
            [self addSubview:self.rbtn];
        }
        if (leftimage) {
            UIButton * lbtn = [UIButton buttonWithType:UIButtonTypeCustom];
            lbtn.frame = CGRectMake(0, 20, 44, 44);
            [lbtn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
            lbtn.tag = LEFTBTN;
            [self addSubview:lbtn];
            
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 12, 44)];
            imageView.contentMode = UIViewContentModeScaleAspectFit;
            imageView.centerY = lbtn.centerY;
            imageView.image = [ImageUtil getImageByName:leftimage];
            [self addSubview:imageView];
        }
        
    }
    return self;
}

-(instancetype)initViewWithTitleName:(NSString*)titlename leftBtnImage:(NSString*)leftimage
{
    if (self = [super init]) {
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 64);
        self.backgroundColor = RGBColor(35, 62, 74);
        titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH  , 44)];
        titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.text = titlename;
        titleLable.font = FontWithNameBold(18);
        titleLable.textColor = [UIColor whiteColor];
        titleLable.backgroundColor = [UIColor clearColor];
        [self addSubview:titleLable];
        
        UIButton * rbtn = [UIButton buttonWithType:UIButtonTypeCustom];
        rbtn.frame = CGRectMake(SCREEN_WIDTH-44, 20, 44, 44);
        [rbtn setImage:[ImageUtil getImageByName:@"ic_sx"] forState:UIControlStateNormal];
        [rbtn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
        rbtn.tag = RIGHTBTN;
        [self addSubview:rbtn];
        
        UIButton * searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        searchBtn.frame = CGRectMake(rbtn.x - 44, 20, 44, 44);
        [searchBtn setImage:[ImageUtil getImageByName:@"ic_search"] forState:UIControlStateNormal];
        [searchBtn addTarget:self action:@selector(searchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:searchBtn];
        
        if (leftimage)
        {
            UIButton * lbtn = [UIButton buttonWithType:UIButtonTypeCustom];
            lbtn.frame = CGRectMake(0, 20, 44, 44);
            [lbtn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
            lbtn.tag = LEFTBTN;
            [self addSubview:lbtn];
            
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 12, 44)];
            imageView.contentMode = UIViewContentModeScaleAspectFit;
            imageView.centerY = lbtn.centerY;
            imageView.image = [ImageUtil getImageByName:leftimage];
            [self addSubview:imageView];
        }
        
    }
    return self;
}
-(instancetype)initViewWithTitleName:(NSString*)titlename leftBtnImage:(NSString*)leftimage rightBtnTitle:(NSString *)title
{
    if (self = [super init]) {
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 64);
        self.backgroundColor = RGBColor(35, 62, 74);
        titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH  , 44)];
        titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.text = titlename;
        titleLable.font = FontWithNameBold(18);
        titleLable.textColor = [UIColor whiteColor];
        titleLable.backgroundColor = [UIColor clearColor];
        [self addSubview:titleLable];
        if (title) {
            UIButton * rbtn = [UIButton buttonWithType:UIButtonTypeCustom];
            rbtn.frame = CGRectMake(SCREEN_WIDTH-70, 20, 70, 44);
            [rbtn setTitle:title forState:UIControlStateNormal];
            rbtn.titleLabel.font = FontWithName(18);
            [rbtn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
            rbtn.tag = RIGHTBTN;
            [self addSubview:rbtn];
        }
        if (leftimage) {
            UIButton * lbtn = [UIButton buttonWithType:UIButtonTypeCustom];
            lbtn.frame = CGRectMake(0, 20, 44, 44);
            [lbtn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
            lbtn.tag = LEFTBTN;
            [self addSubview:lbtn];
            
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 12, 44)];
            imageView.contentMode = UIViewContentModeScaleAspectFit;
            imageView.centerY = lbtn.centerY;
            imageView.image = [ImageUtil getImageByName:leftimage];
            [self addSubview:imageView];
        }
        
    }
    return self;
}


-(instancetype)initCollectionViewWithTitleName:(NSString*)titlename leftBtnImage:(NSString*)leftimage
{
    if (self = [super init]) {
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 64);
        self.backgroundColor = RGBColor(35, 62, 74);
        titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH  , 44)];
        titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.text = titlename;
        titleLable.font = FontWithNameBold(18);
        titleLable.textColor = [UIColor whiteColor];
        titleLable.backgroundColor = [UIColor clearColor];
        [self addSubview:titleLable];
        
        UIButton * rbtn = [UIButton buttonWithType:UIButtonTypeCustom];
        rbtn.frame = CGRectMake(SCREEN_WIDTH-44, 20, 44, 44);
        [rbtn setImage:[ImageUtil getImageByName:@"ic_share"] forState:UIControlStateNormal];
        [rbtn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
        rbtn.tag = RIGHTBTN;
        [self addSubview:rbtn];
        
        self.collectionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.collectionBtn.frame = CGRectMake(rbtn.x - 44, 20, 44, 44);
        [self.collectionBtn setImage:[ImageUtil getImageByName:@"ic_collect_normal"] forState:UIControlStateNormal];
        [self.collectionBtn addTarget:self action:@selector(collectionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.collectionBtn];
        
        if (leftimage)
        {
            UIButton * lbtn = [UIButton buttonWithType:UIButtonTypeCustom];
            lbtn.frame = CGRectMake(0, 20, 44, 44);
            [lbtn addTarget:self action:@selector(clickbtn:) forControlEvents:UIControlEventTouchUpInside];
            lbtn.tag = LEFTBTN;
            [self addSubview:lbtn];
            
            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, 12, 44)];
            imageView.contentMode = UIViewContentModeScaleAspectFit;
            imageView.centerY = lbtn.centerY;
            imageView.image = [ImageUtil getImageByName:leftimage];
            [self addSubview:imageView];
        }
        
    }
    return self;
}


-(void)clickbtn:(UIButton*)sender{
    
    if (navDelegate&&[navDelegate respondsToSelector:@selector(clickNavBtn:)]) {
        [navDelegate clickNavBtn:sender];
    }

}
- (void)searchBtnClick:(UIButton *)btn
{
    if (navDelegate&&[navDelegate respondsToSelector:@selector(clickSearchBtn:)]) {
        [navDelegate clickSearchBtn:btn];
    }
}

- (void)collectionBtnClick:(UIButton *)btn
{
    if (navDelegate&&[navDelegate respondsToSelector:@selector(clickCollectBtn:)]) {
        [navDelegate clickCollectBtn:btn];
    }
}

-(NSString *)description{
     return @"我滴老家，揍住在借个屯";
}

@end
